/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package facade;

import entity.Role;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Tatyana
 */
@Stateless
public class RoleFacade extends AbstractFacade<Role> implements RoleFacadeLocal {
    @PersistenceContext(unitName = "Delta-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public RoleFacade() {
        super(Role.class);
    }
    
    public Role readByName(String roleName){
        Query query = em.createNamedQuery("Role.findByRoleName");
        query.setParameter("roleName", roleName);
        Role role = null;
        try {
            role = (Role) query.getSingleResult();
        } catch (NoResultException ex) {
            return role;
        }
        return role;
    }
    
}
